<template>
  <div class="app-container p-rel">
    <div class="container-title">行政处罚管理</div>
    <form-edit class="p-abs" :detailForm="detailForm" :isEdit="isEdit" @submitForm="submitForm" :editVisible.sync="editVisible" v-if="editVisible"></form-edit>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px">
      <el-row :gutter="15">
        <el-col :lg="8" :xl="6">
          <el-form-item label="文书名称" prop="town">
            <el-input
              v-model="queryParams.town"
              placeholder="请输入文书名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="处罚对象" prop="town">
            <el-input
              v-model="queryParams.town"
              placeholder="请输入处罚对象"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
            <el-button type="primary" icon="" size="" @click="handleQuery">搜索</el-button>
            <el-button icon="" size="" @click="resetQuery">重置</el-button>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8 tableBtnListCss">
      <el-col :span="1.5">
        <el-button type="primary" @click="addBtn">添加</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="index" width="55" align="center"  label="序号"/>
      <el-table-column label="处罚类型" align="center" prop="A"/>
      <el-table-column label="处罚对象" align="center" prop="B" />
      <el-table-column label="处罚对象类型" align="center" prop="C" />
      <el-table-column label="经营地址" align="center" prop="D" />
      <el-table-column label="监管员" align="center" prop="E" />
      <el-table-column label="处罚时间" align="center" prop="F" />
      <el-table-column label="文书名称" align="center" prop="G">
        <template #default="scope">
          <el-button type="text" @click="bookDetailBtn(scope.row)">{{ scope.row.G }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px">
        <template slot-scope="scope">
          <el-button @click="lookDetailBtn(scope.row)" type="text" size="small">查看详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['enterpriseInfo:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/zhangping/zpEnterpriseInfo";
import { categoryList } from "@/api/zhangping/category";
import formEdit from './editFrom.vue'
export default {
  name: "Info",
  dicts: ['enterprise_info_type', 'health_certificate_status', 'business_file_status', 'enterprise_category'],
  components:{ formEdit },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 一企一档表格数据
      infoList: [
        {
          A:"警告",
          B:"漳平市医院",
          C: "放射诊疗",
          D:"漳平市桂林街道林隆南路66号",
          E:"张三",
          F:"2024-01-01",
          G:"文书1"
        },
        {
          A:"罚款",
          B:"漳平市医院",
          C: "传染病防治",
          D:"漳平市桂林街道林隆南路66号",
          E:"张三",
          F:"2024-01-01",
          G:"文书2"
        },
        {
          A:"没收违法所提",
          B:"漳平市医院",
          C: "医疗卫生",
          D:"漳平市桂林街道林隆南路66号",
          E:"张三",
          F:"2024-01-01",
          G:"文书3"
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseName: null,
        creditCode: null,
        type: null,
        typeIdList: [],
        categoryIdList: [],
        category: null,
        town: null,
        townCode: null,
        addr: null,
        legalPerson: null,
        contactNumber: null,
        businessLicense: null,
        sanitaryPermit: null,
        sanitaryPermitDate: null,
        healthCertificateStatus: null,
        archivesStatus: null,
        lastUpdateTime: null,
        userId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      detailForm:{},
      isEdit:false,
      editVisible:false,
      categoryList: [],
    };
  },
  created() {
    this.loading = false
    //this.getList();
    // this.getCategoryList()
  },
  methods: {
    bookDetailBtn(row){
      const obj = {
        path: '/healthCare/test/bookDetail',
        query: {
          id: '111',
        }
      }
      this.$router.push(obj);
    },
    addBtn(){
      const path = '/healthCare/test/detail'
      this.$router.push(path);
    },
    lookDetailBtn(){
      const obj = {
        path: '/healthCare/test/detail',
        query: {
          id: '111',
        }
      }
      this.$router.push(obj);
    },
    /** 查询一企一档列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        enterpriseName: null,
        creditCode: null,
        type: null,
        category: null,
        town: null,
        townCode: null,
        addr: null,
        legalPerson: null,
        contactNumber: null,
        businessLicense: null,
        sanitaryPermit: null,
        sanitaryPermitDate: null,
        healthCertificateStatus: null,
        archivesStatus: null,
        lastUpdateTime: null,
        userId: null,
        createId: null,
        createBy: null,
        createTime: null,
        updateId: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.detailForm = {}
      this.isEdit = false
      this.editVisible = true
    },
    /** 修改按钮操作 */
    handleUpdate(row,type) {
      // this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.detailForm = response.data
        if(type == 1){
          this.isEdit = true
        }else{ // 查看
          this.isEdit = false
        }
        this.editVisible = true

      });
    },
    /** 提交按钮 */
    submitForm(form,id) {
    if (id != null) {
      updateInfo(form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.editVisible = false;
        this.getList();
      });
    } else {
      addInfo(form).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.editVisible = false;
        this.getList();
      });
    }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除一企一档编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('enterpriseInfo/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    },
    getCategoryList(){
      categoryList().then(response => {
        this.categoryList = response.data;
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.app-container{
  .tableBtnListCss{
    margin-top: 10px;
    border-top: 1px solid #e0e0e0;
    padding-top: 10px;
  }
}
</style>